package com.sdlh.demo.spring;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class SpringDemo {

    @Bean("user")
    public User getUser() {
        User user = new User();
        user.setName("zak.z");
        user.setAge(43);
        return user;
    }

    @Data
    static class User {
        private String name;
        private int age;
    }

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext("com.sdlh.demo.spring");
        User bean = (User)context.getBean("user");
        log.info(bean.toString());
    }
}

